/**
 * Created by saturn on 2017/8/8.
 */

import * as axios from '../axios/';
import * as types from '../type/';

// 数据源
const state = {
  mlroot_list: [],
  ml_list: [],
};

const getters = {
  mlroot_list: state => state.mlroot_list,
  ml_list: state => state.ml_list,
};

const actions = {
  getCatalogRootTree({
    commit
  }) {
    axios.getCatalogRootTree(payload => {
      commit(types.MULU_ROOT_TREE, payload);

    })
  },
  getCatalogList({
    commit
  }, id) {
    axios.getCatalogList(id, payload => {
      commit(types.MULU_LIST, payload);
    })
  },
  getCatalogPage({
    commit
  }, param) {
    return new Promise((resolve, reject) => {
      axios.getCatalogPage(param, payload => {
      }).then(data => {
        resolve(data);
      }).catch(err => {
        reject(err);
      });
    });
  },
  getZymlXqDetail({
    commit
  }, param) {
    return new Promise((resolve, reject) => {
      axios.getZymlXqDetail(param, payload => {
      }).then(data => {
        resolve(data);
      }).catch(err => {
        reject(err);
      });
    });
  }
};

const mutations = {
  [types.MULU_ROOT_TREE](state, payload) {
    state.mlroot_list = payload;
  },
  [types.MULU_LIST](state, payload) {
    state.ml_list = payload;
  },
  // [types.catalog_page](state, payload) {
  //   state.catalog_page = payload;
  // }
};

export default {
  state,
  actions,
  mutations,
  getters
}
